/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
    
package be.vdabantwerpen.gow.services;
    
import be.vdabantwerpen.gow.dao.ScoreDAO;
import be.vdabantwerpen.gow.dao.ScoreDAOImpl;
import be.vdabantwerpen.gow.entities.GOWUser;
import be.vdabantwerpen.gow.entities.Post;
import be.vdabantwerpen.gow.entities.Score;
import be.vdabantwerpen.gow.exceptions.ScoreNotFoundException;
import java.util.List;

/**
 *
 * @author Tim.VandenLangenberg
 * @version 1.0
 */
public class ScoreServiceImpl implements ScoreService {
    private final ScoreDAO scoreDAO = new ScoreDAOImpl();
    
    @Override
    public void create(Score score){
        scoreDAO.create(score);
    }
    
    @Override
    public Score read(int scoreId){
        Score score = scoreDAO.read(scoreId);
        if(score == null){
            throw new ScoreNotFoundException();
        }
        return score;
    }
    
    @Override
    public void update(Score score){
        scoreDAO.update(score);
    }
    
    @Override
    public void delete(Score sore){
        scoreDAO.delete(sore);
    }
    
    @Override
    public List<Score> findScoresByUser(GOWUser user){
        List<Score> scores = scoreDAO.findScoresByUser(user);
        if(scores == null || scores.isEmpty()){
            throw new ScoreNotFoundException();
        }
        return scores;
    }
    
    @Override
    public List<Score> findScoresByPost(Post post){
        List<Score> scores = scoreDAO.findScoresbyPost(post);
        if(scores == null || scores.isEmpty()){
            throw new ScoreNotFoundException();
        }
        return scores;
    }
    
}
